﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Castle.ActiveRecord;
using System.ComponentModel.DataAnnotations;
using NHibernate.Criterion;

namespace ZDSoft.LMS.Domain
{
    [ActiveRecord]
    public class TransportOrder : EntityBase  //继承EntityBase，继承的属性和方法
    {
        /// <summary>
        /// 发站
        /// </summary>
        [BelongsTo("StartStationID")]
        public Station StartStation { get; set; }

        /// <summary>
        /// 到站
        /// </summary>
        [BelongsTo("DestionationStationID")]
        public Station DestionationStation { get; set; }

        /// <summary>
        /// 运输方式
        /// </summary>
        [Property]
        [Display(Name = "运输方式")]
        public virtual DeliveryType DeliveryType { get; set; }

        /// <summary>
        /// 发货地点
        /// </summary>
        [Property(NotNull = true, Length = 30)]
        [Required(ErrorMessage = "不能为空！")]
        [StringLength(30, ErrorMessage = "不能超过30个字符!")]
        [Display(Name = "发货地点")]
        public virtual string StartStationLocation { get; set; }

        /// <summary>
        /// 交货地点
        /// </summary>
        [Property(NotNull = true, Length = 30)]
        [Required(ErrorMessage = "不能为空！")]
        [StringLength(30, ErrorMessage = "不能超过30个字符!")]
        [Display(Name = "交货地点")]
        public virtual string DeliveryLocation { get; set; }

        /// <summary>
        /// 托运人
        /// </summary>
        [BelongsTo(Type = typeof(Client), Column = "CommisionedorID", Lazy = FetchWhen.OnInvoke,Insert=true, Update = false)]//接单类与收货人的关系（多对一）
        public Client Commisionedor { get; set; }//托运人

        /// <summary>
        /// 收货人
        /// </summary>
        [BelongsTo(Type = typeof(Client), Column = "ReceiverID", Lazy = FetchWhen.OnInvoke, Update = false)]//接单类与收货人的关系（多对一）
        public virtual Client Receiver { get; set; }

        /// <summary>
        /// 托运人记载事项
        /// </summary>
        [Property(NotNull = true, Length = 1000)]
        [Required(ErrorMessage = "不能为空！")]
        [StringLength(1000, ErrorMessage = "不能超过1000个字符!")]
        [Display(Name = "托运人记载事项")]
        public virtual string CommissionedorRemark { get; set; }

        /// <summary>
        /// 承运人记载事项
        /// </summary>
        [Property(NotNull = true, Length = 1000)]
        [Required(ErrorMessage = "不能为空！")]
        [StringLength(1000, ErrorMessage = "不能超过1000个字符!")]
        [Display(Name = "承运人记载事项")]
        public virtual string TransportorRemark { get; set; }

        [Property(NotNull = true,Length=10)]
        [Required(ErrorMessage = "不能为空！")]
        [Display(Name = "货物价格")]
        public virtual double Price { get; set; }

        [Property(NotNull = true, Length = 1000)]
        [Required(ErrorMessage = "不能为空！")]
        [StringLength(1000, ErrorMessage = "不能超过1000个字符!")]
        [Display(Name = "添附文件")]
        public virtual string AttachedFile { get; set; }

        #region  工单状态，一个订单项就是一个送货单
        /// <summary>
        /// 工单状态，一个订单项就是一个送货单
        /// </summary>
        //[BelongsTo("Status")]
        [Display(Name = "工单状态，一个订单项就是一个送货单")]
        [Property(NotNull = true, ColumnType = "int")]
        [Required(ErrorMessage = "工单状态不能为空！")]
        public virtual TransportOrderStatus Status { get; set; }
        #endregion

        /// <summary>
        /// 创建人
        /// </summary>
        [BelongsTo(Type = typeof(User), Column = "CreatorID", Update = false)]
        public virtual User Creator { get; set; }

        /// <summary>
        /// 运输单项目
        /// </summary>
        [HasMany(typeof(TransportOrderItem), Table = "TranportOrderItem", ColumnKey = "TranportOrderID", Lazy = true, Inverse = true)]
        public virtual IList<TransportOrderItem> TranportOrderItems { get; set; }

        /// <summary>
        /// 调度单
        /// </summary>
        [HasMany(typeof(DeliveryForm), Table = "DeliveryForm", ColumnKey = "TranportOrderID", Lazy = true, Inverse = true)]
        public virtual IList<DeliveryForm> DeliveryFormItems { get; set; }

        [Property]
        public virtual DateTime CreateDate { get; set; }
    }
}
